package com.it.controller;

import cn.dev33.satoken.util.SaResult;
import com.github.pagehelper.PageInfo;
import com.it.bean.Application;
import com.it.bean.Config;
import com.it.mapper.ApplicationMapper;
import com.it.page.PageImpl;
import com.it.page.PageQuery;
import com.it.service.ApplicationService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/app")
public class AppController {

    private final ApplicationService applicationService;

    @PostMapping("/page")
    public SaResult page(@RequestBody PageQuery<Application> pageQuery) {
        PageInfo<Application> pageInfo = applicationService.page(pageQuery);
        return SaResult.data(PageImpl.of(pageInfo));
    }

    @PostMapping("/delete/{id}")
    public SaResult del(@PathVariable("id") Long id) {
        applicationService.delete(id);
        return SaResult.ok();
    }

    @PostMapping("/save")
    public SaResult save(@RequestBody Application application) {
        applicationService.save(application);
        return SaResult.ok();
    }
}